package cn.fengsweb.tokyotyrant
{
	import cn.fengsweb.tokyotyrant.define.TokyoTyrantQueryFunctionName;
	
	import flash.utils.ByteArray;
	
	internal class PutMore
	{
		private var _sendBytesArray:Array
		private var _keyArray:Array;
		
		public function get sendBytes():ByteArray
		{
			return _sendBytesArray.shift();
		}
		public function get key():String
		{
			return _keyArray.shift();
		}
		
		public function PutMore(ValueArray:Array)
		{
			_keyArray		= new Array;
			_sendBytesArray	= new Array();
			
			for(var key:* in ValueArray){
				var key1:String		= String(key);
				var obj1:Object	= ValueArray[key];
				
				var abuf:ByteArray	= new ByteArray();
					abuf.writeUTFBytes(key1);
				
				var query:TokyoTyrantQuery	= new TokyoTyrantQuery(TokyoTyrantQueryFunctionName.PUT);
					query.addArguments(abuf);
					
				for(var key2:* in obj1){
					query.addArguments(Util.string2Bytes(key2));
					query.addArguments(Util.string2Bytes(obj1[key2]));
				}
				
				_keyArray.push(key1);
				_sendBytesArray.push(query.sendBytes);
			}
		}
	}
}